<template>
<div>
<!-- 面包屑 -->
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>权限管理</el-breadcrumb-item>
    <el-breadcrumb-item>权限列表</el-breadcrumb-item>
  </el-breadcrumb>
   <!-- 卡片视图 -->
  <el-card class="box-card" style="width:100%">
     <!-- 搜索和操作用户区域 -->
    <div style="margin-top: 15px;">
       <el-row :gutter="24">
        <el-col :span="9">
          <el-input clearable placeholder="请输入内容"  class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
       </el-row>
    </div>

  <!-- 订单列表区域 -->
  <el-table border stripe
  :data="orders"
  style="width: 100%">
    <el-table-column align="center" type="index" label="#" width="80"></el-table-column>
    <el-table-column align="center" prop="order_number" label="订单编号" width="350"></el-table-column>
    <el-table-column align="center" prop="order_price" label="订单价格" width="100"></el-table-column>
    <el-table-column align="center" label="是否付款" width="180">
      <template slot-scope="scope">
        <el-tag v-if="scope.row.pay_status === '0'" type="danger">未付款</el-tag>
        <el-tag v-else type="success">已付款</el-tag>
      </template>
    </el-table-column>
    <el-table-column align="center" prop="is_send" label="是否发货" width="130"></el-table-column>
    <el-table-column align="center" label="下单时间" width="130">
      <template slot-scope="scope">
         {{scope.row.create_time | dateFormat}}
      </template>
    </el-table-column>
    <el-table-column align="center" label="操作" width="180">
      <!-- 编辑 -->
      <el-button @click="editAddress" size="mini" type="primary" icon="el-icon-edit"></el-button>
      <!-- 删除 -->
      <el-button size="mini" type="success" icon="el-icon-location" @click="exLogClick"></el-button>
    </el-table-column>
  </el-table>

  <!-- 分页功能 -->
  <el-pagination
    @size-change="ordersSizeChange"
    @current-change="ordersCurrentChange"
    :current-page=queryData.pagenum
    :page-sizes="[2, 4, 6, 10]"
    :page-size=queryData.pagesize
    layout="total, sizes, prev, pager, next, jumper"
    :total="total">
    </el-pagination>
  <!-- 编辑功能 -->
  <el-dialog
  title="修改地址"
  :visible.sync="editAddressDialogVisible"
  width="50%">
    <!-- 修改地址的表单 -->
    <el-form :model="editAddressForm" ref="editAddressForm" :rules="editAddressFormRules">
      <el-form-item label="省市区/县" prop="address">
        <el-cascader
        v-model="editAddressForm.editAddressValue"
        :options="cityData"
        @change="AddressChange"></el-cascader>
      </el-form-item>
      <el-form-item label="详细地址" prop="addressDetail">
        <el-input></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="editAddressDialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="editAddressDialogVisible = false">确 定</el-button>
  </span>
 </el-dialog>
 <!-- 物流状态 -->
 <el-dialog
  title="查看物流状态"
  :visible.sync="exLogDialogVisible">
    <el-timeline :reverse="true">
      <el-timeline-item
        v-for="(item, index) in exLogData"
        :key="index"
        :timestamp="item.time">
        {{item.context}}
      </el-timeline-item>
    </el-timeline>
</el-dialog>

  </el-card>
</div>
</template>

<script>
import cityData from './citydata.js'
// console.log(cityData)
export default {
  data () {
    return {
      queryData: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orders: [],
      total: 0,
      editAddressDialogVisible: false,
      // 表单规则
      editAddressFormRules: {
        address: [
          { required: true, message: '请输入地址', trigger: 'blur' }
        ],
        addressDetail: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      // 编辑表单的数据
      editAddressForm: {
        editAddressValue: []
      },
      // 城市数据挂载
      cityData,
      // prop数据,cityData默认是'lable','value'不设置,不用配置选择渲染那个数据
      // props: {
      //   expandTrigger: 'hover'
      // },
      // 查看物流状态
      exLogDialogVisible: false,
      // 物流信息数据
      exLogData: ''

    }
  },

  created () {
    this.getOrdersList()
  },

  methods: {
    // 获取数据
    async getOrdersList () {
      const { data: res } = await this.$axios.get('orders', {
        params: this.queryData
      })
      // console.log(res)
      if (res.meta.status !== 200) return this.$message(res.meta.msg)
      this.orders = res.data.goods
      this.total = res.data.total
    },
    // 页面条数发生变化
    ordersSizeChange (val) {
      // console.log(val)
      this.queryData.pagesize = val
      this.getOrdersList()
    },
    // 页数发生变化
    ordersCurrentChange (val) {
      this.queryData.pagenum = val
      this.getOrdersList()
    },
    // 点击修改地址
    editAddress () {
      this.editAddressDialogVisible = true
    },
    // 修改地址发生改变
    AddressChange () {

    },
    // 获取编辑参数
    getAddress () {

    },
    // 查看物流进度
    async exLogClick () {
      this.exLogDialogVisible = true
      const { data: res } = await this.$axios.get('/kuaidi/1106975712662')
      if (res.meta.status !== 200) return this.$message.error('获取信息失败')
      this.exLogData = res.data
      // console.log(this.exLogData)
    }
  }
}
</script>

<style scoped lang='less'>

</style>
